import json

from kitool.ApiKit import post, get_key_by_path
from kitool.DeepKit import build_line



def get_deep_df(row, conf):
    deep_url = conf['deep_url']
    text = row['病情描述']
    json_object = {'textList' : text}
    json_data = post(deep_url, json_object)
    entity_list = get_key_by_path(json_data, 'ResultData.result.0.entityList')
    res_list = [ build_line(line)  for line in entity_list ]
    return '\n'.join(res_list)


def get_json_df(row, conf):
    nlp_url = conf['nlp_url']
    text = row['病情描述']
    json_object = {'text' : text}
    json_data = post(nlp_url, json_object)
    # 美化 JSON 输出
    pretty_json = json.dumps(json_data, indent=4, ensure_ascii=False)
    return pretty_json